layui.config({
    base: '../../layui/' //此处路径请自行处理, 可以使用绝对路径
}).extend({
    formSelects: 'formSelects-v4'
}).use(['jquery', 'formSelects', 'form','layer'], function () {
    const formSelects = layui.formSelects
        , form = layui.form
        , layer = layui.layer
        , $ = layui.jquery;

    formSelects.on('select1', function (id, vals, val, isAdd, isDisabled) {

    }, true);
    formSelects.data('tableName', 'server', {
        url: '/table/all',
        beforeSuccess: function (id, url, searchVal, result) {
            //我要把数据外层的code, msg, data去掉
            result = result.data;
            //然后返回数据
            return result;
        },
        success: function (id, url, searchVal, result) {
        }
    });
    form.render();

    form.on('submit(add)', function (data) {
        const params = {
            tableName: data.field.tableName,
        };
        submit($, params);
        return false;
    });
    function submit($, params) {
        $.ajax({
            url: '/table/ignoreAdd',
            data: JSON.stringify(params),
            dataType: "json",
            contentType: "application/json;charset=utf-8",
            type: "POST",
            success: function (result) {
                layer.msg(result.data, {icon: 1, time: 1000}, function () {
                    CloseWin();
                })
            }
        })
    }

});

//关闭页面
function CloseWin() {
    parent.location.reload(); // 父页面刷新
    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index); //再执行关闭
}